﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoolERP_Entities;
using CoolERP_DAL;

namespace CoolERP_BLL
{
    public class UsersBLL : BaseBLL<Users>
    {       
        public UsersBLL() { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <param name="iType">1：键盘输入，2：扫描输入</param>
        /// <param name="user"></param>
        /// <returns></returns>
        public int Login(string name, string password, int iType, ref Users user)
        {
            IUsersDAL _dal = new UsersDAL(context);
            return _dal.Login(name, password, iType, ref user);
        }

        public List<Users> GetUsers(Dictionary<string, string> dc, string orderExpr, int? pageIndex, int pageSize, out int totalCount)
        {
            var predicate = PredicateExtensions.True<Users>();
            if (dc.Count > 0)
            {
                if (dc.ContainsKey("Code") && !string.IsNullOrEmpty(dc["Code"]))
                {
                    predicate = predicate.AndEx(t => t.Code==dc["Code"]);
                }
                if (dc.ContainsKey("Name") && !string.IsNullOrEmpty(dc["Name"]))
                {
                    predicate = predicate.AndEx(t => t.Name==dc["Name"]);
                }
            }
            return base.GetPagerList(predicate.Compile(),orderExpr,pageIndex,pageSize,out totalCount);
        }

        /// <summary>
        /// 获取用户权限
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public List<vUserPermission> GetUserPermission(Guid UserId)
        {
            IUsersDAL _dal = new UsersDAL(context);
            return _dal.GetUserPermission(UserId);
        }
    }
}
